<template>
  <view class="container">
    <view class="modify">
      <view class="title">原密码</view>
      <view class="inp">
        <uni-easyinput v-model="oldValue" type="password" placeholder="请输入原密码"></uni-easyinput>
      </view>
    </view>
    <view class="modify">
      <view class="title">新密码</view>
      <view class="inp">
        <uni-easyinput v-model="newValue" type="password" placeholder="请输入新密码"></uni-easyinput>
      </view>
      <view class="inp">
        <uni-easyinput v-model="newValues" type="password" placeholder="再次输入密码"></uni-easyinput>
      </view>
    </view>
    <view @click="submit" class="modifyBtn">
      <view>提交</view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        oldValue: '',
        newValue: '',
        newValues: '',
      }
    },
    methods: {
      submit() {
        if(this.oldValue == '') {
					uni.showToast({
						title: '原密码不能为空',
						icon: 'none',
						duration: 2000
					});
					return
				}
				if(this.newValue == '' | this.newValues == '') {
					uni.showToast({
						title: '新密码不能为空',
						icon: 'none',
						duration: 2000
					});
					return
				}
				if(this.newValue != this.newValues) {
					uni.showToast({
						title: '两次输入密码不一致',
						icon: 'none',
						duration: 2000
					});
					return
				}
			  let tempData = {
          oldPassword: this.oldValue,
					newPassword: this.newValue,
				}
        this.$request.putuserprofile(tempData).then(res => {
          if(res.code == 200){
						uni.showToast({
              title: '修改成功，请重新登录',
              icon: 'none',
              duration: 2000
            })
            setTimeout(() => {
							uni.removeStorageSync('token');
              uni.reLaunch({
								url: '/pages/login/index'
							})
            }, 2000)
					}
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
  .container {
    padding: 0 25rpx;
  }

  .modify {
    padding: 25rpx 0 0;

    .title {
      font-size: 32rpx;
      line-height: 32rpx;
    }

    .inp {
      padding-top: 25rpx;
    }
  }

  .modifyBtn {
    padding-top: 50rpx;

    view {
      width: 100%;
      height: 80rpx;
      line-height: 80rpx;
      text-align: center;
      color: #fff;
      font-size: 32rpx;
      border-radius: 40rpx;
      background-color: #00a0e9;
    }
  }
</style>
